/** 
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */
package com.tompai.common.model;

import java.util.Date;
import java.util.UUID;

import javax.persistence.Id;

import com.fasterxml.jackson.annotation.JsonFormat;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 为所有实体的父类
 * 
 * @author liinux@qq.com
 * @date 2019年12月7日09:36:10
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class BaseModel {

	/**
	 * 主键id
	 */
	@Id
	private String id;

	/**
	 * 创建人
	 */
	private String createBy;

	/**
	 * 创建时间
	 */
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
	private Date createTime;

	/**
	 * 修改人
	 */
	private String updateBy;

	/**
	 * 修改时间
	 */
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
	private Date updateTime;

	/**
	 * 备注
	 */
	private String remark;

	/**
	 * insert 方法执行之前
	 */
	public void beforeInsert() {
		Date date = new Date();
		this.createTime = date;
		this.updateTime = date;
		this.id = UUID.randomUUID().toString().replaceAll("\\-", "");
	}

	/**
	 * update 方法执行之前
	 */
	public void beforeUpdate() {
		Date date = new Date();
		this.updateTime = date;
	}
}
